<template>
	<view class="content">
		<marketOrder :tabs="tabs" :dataConfig="marketConfig" @changeTabs="changeTabs" />

	</view>
</template>

<script>
	import {
		mapActions
	} from "vuex";
	import marketOrder from './components/marketOrder'
	export default {
		components: {
			marketOrder
		},
		data() {
			return {
				marketConfig: {
					page: 1,
					limit: 8,
					total: -1,
					pages: 0,
					list: [],
					loading: false,
					loadStatus: "",
					tabsIndex: 0,
					code: "",
				},
				tabs: [{
						code: '',
						name: '全部'
					},
					{
						code: '0',
						name: '审核中'
					},
					{
						code: '1',
						name: '发布中'
					},
					{
						code: '2',
						name: '已售罄'
					},
					{
						code: '3',
						name: '已取消'
					},
					{
						code: '4',
						name: '已拒绝'
					},
				],
				query: {
					status: '0',
					marketType: '0'
				},
				collectionStatus: {
					'0': '全部',
					'1': '未寄售',
					'2': '寄售中',
					'3': '上链中'
				},
				marketTypeMap: {
					'0': '全部',
					'1': '版权品',
					'2': '衍生品'
				}
			}
		},
		onLoad() {
			this._queryMarketList();
		},
		// 触底事件
		onReachBottom() {
			this._queryMarketList(true);
		},
		onPullDownRefresh() {
			uni.startPullDownRefresh();
			this.initMarketConfig();
			this._queryMarketList();
		},
		methods: {
			...mapActions('user', ['queryMarketList']),
			_queryMarketList(ReachBtm) {
				if (this.marketConfig.loading || this.marketConfig.loadStatus == "nomore") return;
				this.marketConfig.loading = true;
				this.marketConfig.loadStatus = "loading";
				if (ReachBtm) this.marketConfig.page++;
				this.queryMarketList({
					page: this.marketConfig.page,
					limit: this.marketConfig.limit,
					status: this.marketConfig.code,
				}).then(res => {
					this.marketConfig.list = this.marketConfig.list.concat(res.rows);
					this.marketConfig.pages = res.pages;
					this.marketConfig.total = res.total;
					if (this.marketConfig.page >= this.marketConfig.pages) {
						this.marketConfig.loadStatus = "nomore";
					} else {
						this.marketConfig.loadStatus = "loadmore";
					}
				}).finally(() => {
					this.marketConfig.loading = false;
					uni.stopPullDownRefresh();
				})
			},
			changeTabs(item) {
				this.marketConfig.tabsIndex = item.index;
				this.marketConfig.code = item.code;
				this.initMarketConfig();
				this._queryMarketList();
			},
			initMarketConfig() {
				this.marketConfig.page = 1;
				this.marketConfig.total = -1;
				this.marketConfig.pages = 0;
				this.marketConfig.list = [];
				this.marketConfig.loading = false;
				this.marketConfig.loadStatus = "loadmore";
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 0rpx 20rpx 20rpx 20rpx;
	}
</style>
